from django.shortcuts import render
from django.http import JsonResponse
from dashboard import k8s
from dashboard.details import PodListForNode, NodeDetailsInfo
from django.views import View


# from django.utils.decorators import method_decorator
# Create your views here.


@k8s.self_login_required
def node(request):
    return render(request, "k8s/node.html")


# @method_decorator(k8s.self_login_required, name='dispatch')
class NodeDetailsView(View):
    def get(self, request):
        _node = NodeDetailsInfo(request)
        resources = _node.node_resources()
        info = _node.node_info()
        return render(request, "k8s/node_details.html", {'node_resources': resources, 'node_info': info})


class NodeDetailsPodsView(View):
    def get(self, request):
        api = PodListForNode(request)
        return JsonResponse(api.get())


@k8s.self_login_required
def namespace(request):
    return render(request, "k8s/namespace.html")


@k8s.self_login_required
def pv(request):
    return render(request, "k8s/PersistenVolumes.html")


@k8s.self_login_required
def pv_create(request):
    return render(request, "k8s/PersistenVolumesCreate.html")
